using SmartLink.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace SmartLink.Infrastructure.Cache
{
    /// <summary>
    /// 当前操作用户
    /// </summary>
    public class CurrentUser
    {
        /// <summary>
        /// 获取当前操作用户
        /// </summary>
        public static CurrentUserInfo Current
        {
            get
            {
                HttpContext httpContext = HttpContext.Current;
                if (httpContext != null)
                {
                    var token = httpContext.Request.Headers["token"];
                    var userInfo = UserInfoCaches.GetUserInfoCache(token);
                    return userInfo;
                }
                else
                {
                    return _syetemSelf;
                }
            }
        }

        /// <summary>
        /// 当前用户是否是超级管理员
        /// </summary>
        public static bool IsSuperAdmin
        {
            get
            {
                return Current.RoleName.Equals(ConstData.SuperManagerRoleName);
            }
        }

        /// <summary>
        /// 当前用户是否是公司管理员
        /// </summary>
        public static bool IsOrgAdmin
        {
            get
            {
                return Current.RoleName.Equals(ConstData.OrgManagerRoleName);
            }
        }


        private static CurrentUserInfo _syetemSelf = new CurrentUserInfo
        {
            UserId = -10,
            OID = -10,
            //ODID = -10,
            NickName = "系统",
            ROID = -10,
            RoleId = -10,
            RoleName = ConstData.SuperManagerRoleName
        };

        public static CurrentUserInfo System { get { return _syetemSelf; } }
    }
}
